package group.itk.example.redisdemo

import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.redis.core.RedisTemplate

@SpringBootTest
class RedisDemoApplicationTests {

    @Autowired
    @Qualifier("MyRedisConfig")
    private lateinit var redisTemplate: RedisTemplate<String, Any>

    private val user: User = User("Alex", 18)

    @Test
    fun testRedis() {
//        redisTemplate.opsForList().leftPush("list","hello")
//        redisTemplate.opsForValue().set("key1","value1")
        println(redisTemplate.opsForValue().get("key1"))
    }

    @Test
    fun flushDb() {
        redisTemplate.connectionFactory?.connection?.flushDb()
    }

    @Test
    fun testObject() {
//        val str = ObjectMapper().writeValueAsString(user)
//        redisTemplate.opsForValue().set("user",str)
        redisTemplate.opsForValue().set("user",user)
        println(redisTemplate.opsForValue().get("user"))
    }

}
